package com.aiyige.page.mediaslider;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.aiyige.R;
import com.aiyige.page.mediaslider.model.EventPageSelectChange;
import com.aiyige.page.mediaslider.model.Media;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;


public class VideoSliderItemPage extends Fragment implements SelectablePage {
    EventBus eventBus;
    Media media = null;

    public VideoSliderItemPage() {
        eventBus = new EventBus();
    }

    public Media getMedia() {
        return media;
    }

    public void setMedia(Media media) {
        this.media = media;
    }

    public static VideoSliderItemPage newInstance(Media media) {
        VideoSliderItemPage fragment = new VideoSliderItemPage();
        fragment.setMedia(media);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.page_video_slider_item, container, false);


        try {
            eventBus.register(this);
        } catch (Exception e) {

        }
        return view;
    }

    @Override
    public void onDestroyView() {
        try {
            eventBus.unregister(this);
        } catch (Exception e) {

        }
        super.onDestroyView();
    }

    @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
    public void onEvent(EventPageSelectChange event) {
        if (event.isSelected()) {

        } else {

        }
    }

    @Override
    public void onSelectChanged(boolean value) {
        eventBus.postSticky(EventPageSelectChange.newBuilder().selected(value).build());
    }
}
